<template>
	<view class="user-skill pl-lg pr-lg pt-lg" v-if="isLoad">
		<block v-for="(item,index) in list.data" :key="index">
			<view class="list-message flex-warp pt-lg pb-lg" :class="[{'b-1px-t':index!=0}]">
				<image mode="aspectFill" class="item-avatar radius" :src="item.avatarUrl"></image>
				<view class="flex-1 ml-md">
					<view class="flex-between" style="height: 52rpx;">
						<view class="flex-y-center">
							<view class="f-paragraph c-title mr-md max-200 ellipsis">{{item.nickName}}
							</view>
							<view class="flex-warp">
								<i class="iconfont iconyduixingxingshixin icon-font-color"
									:style="{backgroundImage: aindex< item.star?`-webkit-linear-gradient(270deg, #FAD961 0%, #F76B1C 100%)`:`-webkit-linear-gradient(270deg, #f4f6f8 0%, #ccc 100%)`}"
									v-for="(aitem,aindex) in 5" :key="aindex"></i>
							</view>
						</view>
						<view class="f-icontext c-caption">{{item.create_time}}</view>
					</view>
					<view class="flex-warp mt-sm">
						<view class="pt-sm pb-sm pl-md pr-md mt-sm mr-sm radius fill-body f-caption c-desc"
							v-for="(item,index) in item.lable_text" :key="index">{{item}}</view>
					</view>
					<view class="f-caption c-caption mt-md">
						<text decode="emsp" style="word-break:break-all;">{{item.text}}</text>
					</view>
				</view>
			</view>
		</block>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading">
		</load-more>
		<abnor v-if="list.data && list.data.length == 0" :isCenter="true"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import longbingbingServiceListItem from "@/components/longbingbing-service-list-item.vue"
	export default {
		components: {
			longbingbingServiceListItem
		},
		data() {
			return {
				isLoad: false,
				serviceList: [],
				options: {},
				detail: {},
				list: {
					data: []
				},
				param: {
					page: 1,
					coach_id: 0
				},
				loading: true
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		onLoad(options) {
			this.options = options
			this.$util.setNavigationBarColor({
				bg: this.primaryColor
			})
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapActions(['getConfigInfo']),
			...mapMutations(['updateUserItem']),
			async initIndex(refresh = false) {
				await Promise.all([this.getConfigInfo(), this.getList()])
				this.isLoad = true
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex(true)
			},
			async getList() {
				let {
					id: coach_id,
				} = this.options
				let {
					param,
					list: oldList,
				} = this
				param.coach_id = coach_id
				
				let newList = await this.$api.service.commentList(param);
				newList.data.map(item => {
					let have_show_text = item.text.length > 100
					item.have_show_text = have_show_text
					item.showText = !have_show_text
				})
				
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
	}
	.list-message {
		.item-avatar {
			width: 52rpx;
			height: 52rpx;
			background: #f4f6f8;
		}
	
		.iconyduixingxingshixin {
			font-size: 28rpx;
			margin-right: 5rpx;
			font-size: 28rpx;
		}
	}
</style>